package com.yuqian.JavaSe.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class AnimaProxy implements InvocationHandler{
	
	private Object proxy;
	
	AnimaProxy(Object proxy){
		this.proxy = proxy;
	}

	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		System.out.println("开始行为");
		method.invoke(this.proxy, args);
		return null;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		AnimaProxy catP = new AnimaProxy(new Cat());
		Animal c = (Animal)Proxy.newProxyInstance(catP.getClass().getClassLoader(), Cat.class.getInterfaces(),catP);
		c.eat();
		c.run();
	}

}
